package yqt.com.cnki.service.impl;


import haha.life.common.CutPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yqt.com.cnki.bo.KYDABo;
import yqt.com.cnki.bo.QKKMBo;
import yqt.com.cnki.bo.QKYDBo;
import yqt.com.cnki.dao.IWWSJDao;
import yqt.com.cnki.dao.impl.WWSJDaoImpl;
import yqt.com.cnki.po.*;
import yqt.com.cnki.service.IWWSJService;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/11/15 14:03
 * @Version 1.0
 */
@Service
public class WWSJServiceImpl implements IWWSJService {

    @Autowired
    private IWWSJDao wwsjDao;

    @Override
    public List<WWSJPo> getWWSJ_LimitSix() {
        return wwsjDao.getWWSJ_LimitSix();
    }

    //外文数据分页
    public  CutPageBean<WWSJPo>complexSearchWWSJ_List(KYDABo qkydBo){

        String[] sortArr = qkydBo.getSortArr();
        String[] yearArr = qkydBo.getYearArr();
        StringBuffer yearArrBuff = new StringBuffer();
        StringBuffer sortArrStr = new StringBuffer();
        if (sortArr != null && sortArr.length > 0) {
            for (int i = 0; i < sortArr.length; i++) {
                sortArrStr.append("刊名 = ").append("\"").append(sortArr[i]).append("\"").append(" or ");
            }
            if (sortArrStr.length() > 3) {
                String ortArrStr = sortArrStr.substring(0, sortArrStr.length() - 3);
                qkydBo.setSortArrStr(ortArrStr);
            }
        }
        if (yearArr != null && yearArr.length > 0) {
            for (int i = 0; i < yearArr.length; i++) {
                yearArrBuff.append("年 =").append(yearArr[i]).append(" or ");
            }
            if (yearArrBuff.length() > 3) {
                String yearArrStr = yearArrBuff.substring(0, yearArrBuff.length() - 3);
                qkydBo.setYearArrStr(yearArrStr);
            }
        }
        CutPageBean<WWSJPo> cutPageBean = new CutPageBean();
        qkydBo.setStart(qkydBo.getPage(), qkydBo.getPageSize());
        List<WWSJPo>list=   wwsjDao.complexSearchWWSJ_List(qkydBo);
        int count = (int) wwsjDao.complexSearchWWSJ_Count(qkydBo);
        cutPageBean.initCutPage(count, qkydBo.getPageSize(), list);
        return  cutPageBean;
    }

    /**
     *
     *获取期刊刊名
     *@author cb
     *date 2022/2/23
     */
    public List<QKKMPo> getQKKM(){
        return  wwsjDao.getQKKM();
    }

    //期刊刊名分页
    public  CutPageBean<QKKMPo>getQKKMpageList(QKKMBo qkkmBo){

        StringBuffer sortArrStr = new StringBuffer();

        CutPageBean<QKKMPo> cutPageBean = new CutPageBean();
        qkkmBo.setStart(qkkmBo.getPage(), qkkmBo.getPageSize());
        List<QKKMPo>list=   wwsjDao.getQKKMpageList(qkkmBo);
        int count = (int) wwsjDao.getQKKMpageList_Count(qkkmBo);
        cutPageBean.initCutPage(count, qkkmBo.getPageSize(), list);
        return  cutPageBean;
    }

    @Override
    public List<KeyValuePo> getYearForeign(String km) {
        return wwsjDao.getYearForeign(km);
    }



    @Override
    public FZWUFILE getFZWUFILE(String fileId) {
        return wwsjDao.getFZWUFILE(fileId);
    }

    public FZFile getFZFile(String drid){
        return   wwsjDao.getFZFile(drid);
    }

    @Override
    public String getMetaIdByDrid(String drid) {
        return wwsjDao.getMetaIdByDrid(drid);
    }
}
